//
//  CommentTableViewCell.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/5.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "CommentTableViewCell.h"
#import "NewActionOfCommentModel.h"
#import "HotCommentTableViewCell.h"
#import "TAMacro.h"
@interface CommentTableViewCell ()
<
    UITableViewDelegate,
    UITableViewDataSource
>

@property (nonatomic, strong) UITableView *commentTableView;

@end


@implementation CommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.917 alpha:1.000];
        [self createView];
        
    }
    return self;
}

- (void)createView {
    
    _commentTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _commentTableView.backgroundColor = [UIColor whiteColor];
    _commentTableView.delegate = self;
    _commentTableView.dataSource = self;
    [self.contentView addSubview:_commentTableView];
    [_commentTableView registerNib:[UINib nibWithNibName:@"HotCommentTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CommentTableViewCellReuse"];
    _commentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _commentTableView.scrollEnabled = NO;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_commentArray.count == 0) {
        return 0;
    }
    return 20;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_commentArray.count == 0) {
        return 0;
    } else if (_commentArray.count < 4) {
        return _commentArray.count;
    }
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HotCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommentTableViewCellReuse"];
    cell.commentModel = _commentArray[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
    NSLog(@"跳转页面cell");
}

- (void)setCommentArray:(NSArray<NewActionOfCommentModel *> *)commentArray {
    _commentArray = commentArray;
    [_commentTableView reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _commentTableView.frame = CGRectMake(10, 0, self.contentView.bounds.size.width - 20, self.contentView.bounds.size.height);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
